package com.keta.foundation.util;

import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.keta.foundation.service.impl.ModelServiceImpl;

public class JsonUtil {

	private static ObjectMapper objectMapper = new ObjectMapper();
	private static Logger log = LoggerFactory.getLogger(ModelServiceImpl.class);

	/*
	 * List中的Poji对象需使用Jackson注解标注
	 */
	public static <T> String PojoList2Json(List<T> list) {
		try {
			return objectMapper.writeValueAsString(list);
		} catch (Exception e) {
			log.error("Poji List转Json发生异常" + Exceptions.getStackTraceAsString(e));
		}
		return null;
	}

	/*
	 * Poji对象需使用Jackson注解标注
	 */
	public static <T> String Pojo2Json(T obj) {
		try {
			return objectMapper.writeValueAsString(obj);
		} catch (Exception e) {
			log.error("Poji转Json发生异常" + Exceptions.getStackTraceAsString(e));
		}
		return null;
	}

}
